package test;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * Created by Kong1997 on 2017/7/7.
 */
public class Equip {
    public int x = (int) (10 + Math.random() * 400);
    public int y = -(int) (10 + Math.random() * 200);

    public int equipClass = 0;  //装备种类   0双弹  1炸弹

    public int status = 1;   //存在状态

    public int count = 0;  //炸弹数量

    BufferedImage imgs[] = new BufferedImage[3];   //保存装备图片

    public Equip() {   //装备构造函数
        try {
            imgs[0] = ImageIO.read(getClass().getResource("/blue.png"));
            imgs[1] = ImageIO.read(getClass().getResource("/red.png"));
            imgs[2] = ImageIO.read(getClass().getResource("/en.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //绘制装备
    public void paint(Graphics g) {
        if (status == 1) {
            g.drawImage(imgs[equipClass], x, y, null);   //绘制装备
            y += 3;
            if (y > 652) {
                equipClass = Math.random() > 0.5 ? 1 : 0;   //随机出现装备的位置  以及装备种类
                x = (int) (10 + Math.random() * 400);
                y = -(int) (100 + Math.random() * 400);
            }
        } else {
            g.drawImage(null, x, y, null);    //捡装备后 消失
            if (equipClass == 1) {  //如果是炸弹
                count++;
            }
            equipClass = Math.random() > 0.5 ? 1 : 0;          //掉落新的装备
            status = 1;
            x = (int) (10 + Math.random() * 400);
            y = -(int) (100 + Math.random() * 400);
        }

        //绘制炸弹道具 计数
        g.drawImage(imgs[2], 5, 580, null);
        g.setColor(Color.white);
        g.setFont(new Font("Verdang", Font.BOLD, 20));
        g.drawString("x" + count, 60, 600);


    }


}
